/*
 * Copyright (c) 2010, Nikolaus Moll
 * All rights reserved.
 */
package net.gradecalculator.plugin.core.srdx.internal;

import java.util.LinkedList;
import java.util.List;

import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlElementWrapper;
import javax.xml.bind.annotation.XmlElements;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;
import javax.xml.bind.annotation.XmlType;

@XmlRootElement(namespace = "http://gradecalculator.net/", name="module")
@XmlType( 
 name = "module",
 propOrder = { "name", "courses" } 
) 
public class XmlModule implements IXmlModuleListItem, IXmlModuleIdentificator {
	private List<XmlCourse> courses = new LinkedList<XmlCourse>();
	private String name;
	
	private IXmlModuleIdentificator parent;
	
	@Override
	@XmlTransient
	public IXmlModuleIdentificator getParent()
	{
		return parent;
	}
	@Override
	public void setParent(final IXmlModuleIdentificator parent)
	{
		this.parent = parent;
	}

	@Override
	@XmlElement(name = "name") 
	public String getName() {
		return name;
	}
	public void setName(final String name) {
		this.name = name;
	}
	
	@XmlElementWrapper(name = "courses") 
	@XmlElements({
           @XmlElement(name="course",type=XmlCourse.class),
           @XmlElement(name="individualcourse",type=XmlIndividualCourse.class)
       })
	public List<XmlCourse> getCourses()
	{
		return courses;
	}

	@Override
	public String getIdentifier() {
		if (parent != null) {
			return parent.getIdentifier() + "." + name;
		}
		return name;
	}

}
